﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.Windows.Controls.Primitives;
//using Microsoft.Expression.Interactivity.Core;

namespace VideoChatClient
{
	public class StartIpReciveBehavior : Behavior<ToggleButton>
	{
        public enum ReciveTypes { Audio, Video };
        public StartIpReciveBehavior()
		{
			// Insert code required on object creation below this point.

			//
			// The line of code below sets up the relationship between the command and the function
			// to call. Uncomment the below line and add a reference to Microsoft.Expression.Interactions
			// if you choose to use the commented out version of MyFunction and MyCommand instead of
			// creating your own implementation.
			//
			// The documentation will provide you with an example of a simple command implementation
			// you can use instead of using ActionCommand and referencing the Interactions assembly.
			//
			//this.MyCommand = new ActionCommand(this.MyFunction);
		}

        #region ReciveType
        private ReciveTypes reciveType = ReciveTypes.Video;
        public ReciveTypes ReciveType
        {
            get { return reciveType; }
            set
            {
                if (reciveType == value) return;
                reciveType = value;
            }
        }
        #endregion

		protected override void OnAttached()
		{
			base.OnAttached();

            AssociatedObject.Checked += (_1, _2) => 
            {
                switch (ReciveType)
                {
                    case ReciveTypes.Audio:
                        App.ViewModel.IsIpAudioRecived = true;
                        break;
                    case ReciveTypes.Video:
                        App.ViewModel.IsIpVideoRecived = true;
                        break;
                    default:
                        MessageBox.Show("Ошибка в StartIpReciveBehavior. Тип " + ReciveType.ToString() + " не поддерживается");
                        break;
                }
            };


            AssociatedObject.Unchecked += (_1, _2) =>
            {
                switch (ReciveType)
                {
                    case ReciveTypes.Audio:
                        App.ViewModel.IsIpAudioRecived = false;
                        break;
                    case ReciveTypes.Video:
                        App.ViewModel.IsIpVideoRecived = false;
                        break;
                    default:
                        MessageBox.Show("Ошибка в StartIpReciveBehavior. Тип " + ReciveType.ToString() + " не поддерживается");
                        break;
                }
            };
		}

		protected override void OnDetaching()
		{
			base.OnDetaching();

			// Insert code that you would want run when the Behavior is removed from an object.
		}
	}
}